package com.feihong.txgw.anim;

import android.animation.Animator;
import android.support.v7.widget.RecyclerView;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import com.adapter.base.animation.BaseAnimation;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName TxListAnimation
 * @package com.feihong.txgw.anim
 * @data 2018/7/19 17:49
 * @Describe  通讯顾问   列表动画  基于recyclerView
 * @Change
 */
public class TxListAnimation {

    private int mDuration = 300;
    private BaseAnimation mAnimation;
    /**
     * 是否只是首次加载的时候启动动画
     */
    private boolean isFirstOnly = false;
    private Interpolator mInterpolator = new LinearInterpolator();
    public void addAnimation(BaseAnimation animation){
        mAnimation = animation;
    }

    private int mLastPosition = -1;
    public void setHolder(RecyclerView.ViewHolder viewHolder){
        if(viewHolder.getLayoutPosition() > mLastPosition || !isFirstOnly){
            for(Animator animator : mAnimation.getAnimators(viewHolder.itemView)){
                startAnim(animator);
            }
            mLastPosition = viewHolder.getLayoutPosition();
        }
    }

    public void setFirstOnly(boolean firstOnly){
        isFirstOnly = firstOnly;
    }
    private void startAnim(Animator anim) {

        anim.setDuration(mDuration).start();
        anim.setInterpolator(mInterpolator);
    }

}
